home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
ctlib100.zip
/
INSTALL.LZH
/
CTBPTREE.INT
< prev
next >
Wrap
Text File
|
1996-10-12
|
6KB
|
146 lines
{**************************************************************************}
{* BitSoft Development, L.L.C. *}
{* Copyright (C) 1995, 1996 BitSoft Development, L.L.C. *}
{* All rights reserved. *}
{* B+ Trees Unit *}
{* Version 1.0.4 *}
{**************************************************************************}
unit ctBpTree;
{$X+}
interface
uses Objects,
{$ifdef ver60} BsdVer60, {$endif}
Containr, ctBTrees, ctTrees;
type
PLinkedBlock = ^TLinkedBlock;
TLinkedBlock = object(TObject)
ID : LongInt;
NextBlock : LongInt;
PrevBlock : LongInt;
Owner : Pointer;
Count : Word;
Data : PChar;
Modified : Boolean;
constructor Init (AOwner : Pointer);
destructor Done; virtual;
function At (Index : Word) : Pointer; virtual;
procedure AtCopyBlock(Index, SourceIndex : Word; SourceBlock :
PLinkedBlock; ItemCount : Word);
procedure AtDelete(Index: Word);
procedure AtDeleteBlock(Index, ItemCount : Word);
procedure AtInsert(Index : Word; Item : Pointer);
procedure AtPut (Index : Word; Item : Pointer); virtual;
procedure FreeAll; virtual;
procedure Insert (Item : Pointer);
function IsFull : Boolean;
function LoadData (AOffset : LongInt): Boolean; virtual;
function Search (Key : Pointer; var Index : Word) : Boolean; virtual;
function StoreData: Boolean; virtual;
end; { TLinkedBlock }
type
PmWayKeyNode = ^TmWayKeyNode;
TmWayKeyNode = object (TmWayNode)
function GetKey(Item : Pointer) : Pointer; virtual;
end; { TmWayKeyNode }
const
TBPlusTreeSig : array [0..10] of Char = 'ctBPlusTree';
const
TBPlusTreeVer = $0100;
type
PBPlusTree = ^TBPlusTree;
TBPlusTree = object(TBaseBTree)
constructor Init (ADegree, ABlockSize, ADataSize, AKeySize : Word;
AStream : PStream; IndexBufferSize, DataBufferSize : LongInt);
constructor Open (AStream : PStream; IndexBufferSize,
DataBufferSize : LongInt);
destructor Done; virtual;
function Delete (Item : Pointer) : Boolean; virtual;
function DeleteAll : Boolean; virtual;
function DeleteAllThat (Test: Pointer): Boolean; virtual;
function Find (Key : Pointer; var Hits : LongInt) : Boolean;
virtual;
function FindThat (Key, Test : Pointer; var Hits : LongInt) :
Boolean; virtual;
function First : Pointer; virtual;
function FirstThat (Test : Pointer) : Pointer; virtual;
procedure Flush; virtual;
function FreeAll : Boolean; virtual;
function FreeAllThat (Test: Pointer): Boolean; virtual;
function ForEach (Action: Pointer): Boolean; virtual;
function ForEachThat (Test, Action : Pointer): Boolean; virtual;
function Height : Word; virtual;
function Insert (Item : Pointer) : Boolean; virtual;
function ItemReplace (OldItem, NewItem : Pointer) : Boolean; virtual;
function KeyFirst (Key : Pointer) : Pointer; virtual;
function KeyLast (Key : Pointer) : Pointer; virtual;
function Last : Pointer; virtual;
function LastThat(Test : Pointer) : Pointer; virtual;
function Next (Item : Pointer) : Pointer; virtual;
function NextThat(Test : Pointer; Item : Pointer) : Pointer; virtual;
function NewBlock : PLinkedBlock; virtual;
function NewNode : PmWayNode; virtual;
function Prev (Item : Pointer) : Pointer; virtual;
function PrevThat(Test : Pointer; Item : Pointer) : Pointer; virtual;
private
BlockSize : Word;
BlockDataSize : Word;
CurrentBlock : PLinkedBlock;
FirstBlock : LongInt;
BlockBuffer : PCollection;
BlockBufferSize : LongInt;
FreeBlocks : LongInt;
function BlockStoredSize : Word; virtual;
function ConcatenateBlock : Boolean;
procedure GetBlock (ID : LongInt);
function GetNewBlock : PLinkedBlock;
function InitTree (ABlockBufferSize : LongInt): Boolean;
function LocateFirst (Key : Pointer; var Index : Word) : Boolean;
function LocateItem (Item : Pointer; var Index : Word) : Boolean;
function LocateLast (Key : Pointer; var Index : Word) : Boolean;
procedure ReadHeader; virtual;
function RedistributeBlockEmpty (var NewKey : Pointer) : Boolean;
function RedistributeBlockFull (Item : Pointer; Index : Word;
var NewKey : Pointer) : Boolean;
procedure ReleaseBlock (Block : PLinkedBlock);
function SplitBlock (Item : Pointer; Index : Word; var NewKey : Pointer;
var ChildNode : LongInt) : Boolean;
function ValidSignature (ASignature : PChar) : Boolean;
function ValidVersion (AVersion : Word) : Boolean;
procedure WriteHeader; virtual;
end; { TBPlusTree }
type
PObjectBPlusTree = ^TObjectBPlusTree;
TObjectBPlusTree = object(TBPlusTree)
constructor Init (ADegree, ABlockSize, ADataSize, AKeySize : Word;
AStream : PStream; IndexBufferSize, DataBufferSize : LongInt);
procedure FreeItem (Item : Pointer); virtual;
function GetItem (var S : TStream) : Pointer; virtual;
function NewBlock : PLinkedBlock; virtual;
procedure PutItem (var S : TStream; Item : Pointer); virtual;
private
function BlockStoredSize : Word; virtual;
end; { TObjectBPlusTree }
type
PLinkedObjectBlock = ^TLinkedObjectBlock;
TLinkedObjectBlock = object(TLinkedBlock)
function At (Index : Word) : Pointer; virtual;
procedure AtPut (Index : Word; Item : Pointer); virtual;
procedure FreeAll; virtual;
function LoadData (AOffset : LongInt): Boolean; virtual;
function StoreData: Boolean; virtual;
end; { TLinkedObjectBlock }
implementation
end.